import axios from 'axios'
import qs from 'qs'
import { ElMessage } from 'element-plus'

const service = axios.create({
  baseURL: 'http://49.232.154.120:8080',
  timeout: 50000
})

service.interceptors.response.use(
  response => response.data,
  error => {
    ElMessage.error(error.response?.data?.message || error.message)
    return Promise.reject(error)
  }
)

export function get(url, params = {}, config = {}) {
  return service.get(url, {
    params,
    paramsSerializer: p => qs.stringify(p, { arrayFormat: 'repeat' }),
    ...config
  })
}

export function post(url, data = {}, config = {}) {
  return service.post(url, data, config)
}

export default service